<?

include_once "rbns_engine.php5"; 

//
// and RBNS main visible class




class RBNS_exception extends RBNS_engine{
// template parser class definition


  
function __construct() {
 
   parent::__construct();
   
}

private $defultExeptionMethod="exceptionDefault";

protected $exceptionMethods=array("RBNS_Exception_Default"=>"exceptionDefault");

private $exceptionPoint=array();

/**
 *  Throw Exception.
 *  After exception throwed it will catch in nearly getTemplate function.
 *  Effect of catching is template of exception getting instead template of running method .
 *  
 *  $exceptionName will be key of $exceptionMethods array.
 *  If $exceptionName is not present in $exceptionMethods 
 *  will get temlate for exceptionDefault method.
 *
 * @param string $exceptionName
 */
function throwException($exceptionName){
	if(!is_array($this->exceptionPoint)) $this->exceptionPoint=array();
    array_push($this->exceptionPoint,$exceptionName);

}


/**
 * Add pair $exceptionName and $exceptionMethodName to $exceptionMethods.
 *
 * @param string $exceptionName  
 * @param string $exceptionMethodName
 */
function addException($exceptionName,$exceptionMethodName=''){
	if(empty($exceptionMethodName)) $exceptionMethodName=$exceptionName;
	$this->exceptionMethods[$exceptionName]=$exceptionMethodName;
	
}

/**
 * Erase $exceptionName from $exceptionMethods;
 *
 * @param string $exceptionName
 */
function eraseException($exceptionName){
	if(!empty($this->exceptionMethods[$exceptionName])) unset($this->exceptionMethods[$exceptionName]);
}

function exceptionDefault(){
	$ToRBNSParsing=$this->gettemplate(__METHOD__);  
    include(_RBNS_PARSERPATH);
}




function getTemplate($method){
    if(!empty($this->exceptionPoint)){ 
         $mn=array_pop($this->exceptionPoint);

    	 $method=$this->exceptionMethods[$mn];    	
    	 
    	
    	 
         if(!method_exists($this,$method)) $method=$this->defultExeptionMethod;
    	 $s=parent::getTemplate($method);
    	 $this->exceptionPoint=0;
    	 return $s;
    }
    else return parent::getTemplate($method);
} 


} 

?>